<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>菜单/云端管理</h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>
            首页</a></li>
        <li><a href="#">云端管理</a></li>
        <li class="active">菜单/服务器管理</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-body box-profile" style="padding: 20px;">
                    <h2 style="margin: 4px 0 20px">基本配置</h2>
                    <p>你的服务器可以通过云端接口查询设备和用户数据，或向设备下发指令。</p>
                    <div style="border: 1px solid #ebecec;padding: 16px;color: #373d41;">
                        <h5 style="margin:0 0 16px 0;font-weight: 700">线上环境</h5>
                        <p style="margin-bottom: 5px">
                            <span style="opacity: .5;">云端唯一身份（AppKey）：</span>
                            <span style="opacity: .5;" class="appKey"></span>
                        </p>
                        <p style="margin-bottom: 0px">
                            <span style="opacity: .5;">云端密码（AppSecret）：</span>
                            <span style="opacity: .5;">***</span>&nbsp;&nbsp;
                            <span style="cursor: pointer;color: rgb(0, 204, 153)" class="appSecret">查看</span>
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-body box-profile" style="padding: 20px;">
                    <h2 style="margin: 4px 0 20px">数据实时推送配置</h2>
                    <p style="margin-bottom: 28px;">配置URL后，该账号下产生的所有设备实时数据，都会通过HTTP推送到该地址。</p>
                    <div style="padding-bottom: 80px;color: #373d41;">
                        <span>服务器地址（URL）：</span>
                        <span class="pushUrl"></span>
                        <button type="button" class="btn btn-default">修改配置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /.row -->

</section>

<script>
    var appSecret;
    var pushUrl;
    var urlReg=/(http|https):\/\/[^\s]+.[^\s]+/;
    AsyncGet("/app/appKey", null, function (result) {
        $(".appKey").text(result.appKey);
        $(".pushUrl").text(result.pushUrl);
        appSecret = result.appSecret;
        pushUrl = result.pushUrl;
    })
    $(".appSecret").click(function () {
        var param = {
            title: "<p style='font-weight: 700;word-break: break-all;padding: 3px 16px 0 0;margin: 0;'>云端密码（AppSecret）：" + appSecret + "</p>",
            width: 410,
            text: "<p>开发者密码是校验云端身份的密码，具有极高的安全性。切记勿把密码直接交给第三方开发者或直接存储在代码中。</p>"
        }
        modals.info(param);
    })
    $("button").click(function () {
        var param = {
            ok_label: "保存",
            title: "<p>修改配置</p>",
            width: 710,
            text: "<form class='form-horizontal' role='form' id='pushUrlForm'>" +
                "<div class='form-group'>" +
                "<label  class='col-xs-3 control-label'>服务器地址（URL）:</label>" +
                "<div class='col-sm-9'>" +
                "<input type='text'class='form-control' name='pushUrl' value='" + NullToBlank(pushUrl) + "'/>" +
                "</div>",
            callback: function (model) {
                var url=$(model).find("[name='pushUrl']").val();
                if (!urlReg.test(url)) {
                    modals.error("请检查URL格式，仅支持http://或https://开头的URL");
                    return;
                }
                AsyncPut("/app/pushUrl", {pushUrl: url}, function () {
                    pushUrl=url;
                    $(".pushUrl").text(pushUrl);
                    modals.correct("修改成功");
                })
            }
        }
        modals.confirm(param);
    })
</script>
